/**
 * Copyright (c) 2018-2028.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sailmi.log.controller;

import com.sailmi.common.model.log.LogApiInfo;
import com.sailmi.common.model.log.LogErrorInfo;
import com.sailmi.common.model.log.LogUsualInfo;
import com.sailmi.common.tool.api.R;
import com.sailmi.common.tool.utils.BeanUtil;
import com.sailmi.log.entity.LogApi;
import com.sailmi.log.entity.LogError;
import com.sailmi.log.entity.LogUsual;
import com.sailmi.log.service.ILogApiService;
import com.sailmi.log.service.ILogUsualService;
import com.sailmi.log.service.ILogErrorService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 日志服务Feign实现类
 *
 * @author yzh
 */
@RestController

public class LogController {
	private static final String API_PREFIX="";
	ILogUsualService usualLogService;

	ILogApiService apiLogService;

	ILogErrorService errorLogService;

	public LogController(ILogUsualService usualLogService, ILogApiService apiLogService, ILogErrorService errorLogService) {
		this.usualLogService = usualLogService;
		this.apiLogService = apiLogService;
		this.errorLogService = errorLogService;
	}


	@PostMapping(API_PREFIX + "/saveUsualLog")
	public R<Boolean> saveUsualLog(@RequestBody LogUsualInfo log) {
		LogUsual logUsual = new LogUsual();
		BeanUtil.copyProperties(log,logUsual);
		logUsual.setParams(logUsual.getParams().replace("&amp;", "&"));
		return R.data(usualLogService.save(logUsual));
	}


	@PostMapping(API_PREFIX + "/saveApiLog")
	public R<Boolean> saveApiLog(@RequestBody LogApiInfo log) {
		LogApi logApi = new LogApi();
		BeanUtil.copyProperties(log,logApi);
		logApi.setParams(logApi.getParams().replace("&amp;", "&"));
		return R.data(apiLogService.save(logApi));
	}


	@PostMapping(API_PREFIX + "/saveErrorLog")
	public R<Boolean> saveErrorLog(@RequestBody LogErrorInfo log) {
		LogError logError = new LogError();
		BeanUtil.copyProperties(log,logError);
		logError.setParams(logError.getParams().replace("&amp;", "&"));
		return R.data(errorLogService.save(logError));
	}
}
